package com.spzx.user.controller;

import java.util.List;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.spzx.common.security.annotation.InnerAuth;
import com.spzx.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.spzx.user.api.domain.UserAddress;
import com.spzx.user.service.IUserAddressService;
import com.spzx.common.core.web.controller.BaseController;
import com.spzx.common.core.web.domain.AjaxResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;

/**
 * 用户地址Controller
 *
 * @author atguigu
 * @date 2024-07-03
 */
@Tag(name = "用户地址接口管理")
@RestController
@RequestMapping("/userAddress")
public class UserAddressController extends BaseController {
    @Autowired
    private IUserAddressService userAddressService;


    @InnerAuth
    @Operation(summary = "内部调用接口：查询用户地址详情信息")
//    @RequiresPermissions("user:userAddress:list")
    @GetMapping("/id/")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(userAddressService.getById(id));
    }


    /**
     * 查询用户地址列表
     */
    @Operation(summary = "查询用户地址列表")
//    @RequiresPermissions("user:userAddress:list")
    @GetMapping("/list")
    public AjaxResult list() {
        List<UserAddress> addresses = userAddressService.list(Wrappers.lambdaQuery(UserAddress.class)
                .eq(UserAddress::getUserId, SecurityUtils.getUserId()));

        return success(addresses);
    }


    /**
     * 新增用户地址
     */
    @Operation(summary = "新增用户地址")
//    @RequiresPermissions("user:userAddress:add")
//    @Log(title = "用户地址", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserAddress userAddress) {
        return toAjax(userAddressService.saveAddress(userAddress));
    }
//
//    /**
//     * 导出用户地址列表
//     */
//    @Operation(summary = "导出用户地址列表")
//    @RequiresPermissions("user:userAddress:export")
//    @Log(title = "用户地址", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, UserAddress userAddress)
//    {
//        List<UserAddress> list = userAddressService.selectUserAddressList(userAddress);
//        ExcelUtil<UserAddress> util = new ExcelUtil<UserAddress>(UserAddress.class);
//        util.exportExcel(response, list, "用户地址数据");
//    }
//
//    /**
//     * 获取用户地址详细信息
//     */
//    @Operation(summary = "获取用户地址详细信息")
//    @RequiresPermissions("user:userAddress:query")
//    @GetMapping(value = "/{id}")
//    public AjaxResult getInfo(@PathVariable("id") Long id)
//    {
//        return success(userAddressService.getById(id));
//    }
//
//
//
//    /**
//     * 修改用户地址
//     */
//    @Operation(summary = "修改用户地址")
//    @RequiresPermissions("user:userAddress:edit")
//    @Log(title = "用户地址", businessType = BusinessType.UPDATE)
//    @PutMapping
//    public AjaxResult edit(@RequestBody UserAddress userAddress)
//    {
//        return toAjax(userAddressService.updateById(userAddress));
//    }
//
//    /**
//     * 删除用户地址
//     */
//    @Operation(summary = "删除用户地址")
//    @RequiresPermissions("user:userAddress:remove")
//    @Log(title = "用户地址", businessType = BusinessType.DELETE)
//	@DeleteMapping("/{ids}")
//    public AjaxResult remove(@PathVariable Long[] ids)
//    {
//        return toAjax(userAddressService.removeBatchByIds(Arrays.asList(ids)));
//    }
}
